package com.sxdx.common;



import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> implements Serializable {

    private Integer code; //编码：200成功，201和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> Result<T> success(T object) {
        Result<T> r = new Result<T>();
        r.data = object;
        r.code = 200;
        return r;
    }

    public static <T> Result<T> error(String msg) {
        Result r = new Result();
        r.msg = msg;
        r.code = 201;
        r.data=null;
        return r;
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

    /**
     * 未登陆
     * @param
     * @return
     * @param <T>
     */
    public static <T> Result<T> RE410() {
        Result r = new Result();
        r.msg = "未登录";
        r.code = 410;
        r.data=null;
        return r;
    }

    /**
     * 未登陆
     * @param
     * @return
     * @param <T>
     */
    public static <T> Result<T> RE411() {
        Result r = new Result();
        r.msg = "登陆过期";
        r.code = 411;
        r.data=null;
        return r;
    }

}
